package org.hhchat.others.baidu;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * Created this one by HMH on 2017/9/27.
 */
public class exam2 {

    public static int putCatalyst(int numOfLines, List<Integer> startXPoints, List<Integer> endXPoints) {
        int[][] points = new int[numOfLines][2];
        for (int i = 0; i < numOfLines; i++) {
            points[i][0] = startXPoints.get(i);
            points[i][1] = endXPoints.get(i);
        }
        Arrays.sort(points, (a, b) -> (a[0] - b[0]));
        int count = 0;
        Integer pre = null;
        for (int i = 0; i < points.length; i++) {
            if (pre != null) {
                if (pre >= points[i][0]) {
                    pre = Math.min(pre, points[i][1]);
                } else {
                    count++;
                    pre = points[i][1];
                }
            } else {
                count++;
                pre = points[i][1];
            }
        }
        return count;
    }

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        List<Integer> startXPoints = new ArrayList<>();
        List<Integer> endXPoints = new ArrayList<>();
        startXPoints.add(1);
        startXPoints.add(1);
        startXPoints.add(4);
        startXPoints.add(5);

        endXPoints.add(2);
        endXPoints.add(3);
        endXPoints.add(9);
        endXPoints.add(10);

        System.out.println(putCatalyst(4, startXPoints, endXPoints));
    }
}
